//
//  SSSRecordOrderToRecordSearchBar.m
//  SSSMerchant
//
//  Created by 谢曦 on 2017/3/25.
//  Copyright © 2017年 xnxin. All rights reserved.
//

#import "SSSRecordOrderToRecordSearchBar.h"
#define  kSearchViewW 70
@interface SSSRecordOrderToRecordSearchBar()
@property (nonatomic,weak) UILabel *beginLable;
@property (nonatomic,weak) UILabel *endLable;
@end
@implementation SSSRecordOrderToRecordSearchBar

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        [self setUI];
        self.layer.cornerRadius=4;
        self.layer.borderWidth=1;
        self.layer.borderColor=ThemeGreenColor.CGColor;
    }
    return self;
}
-(void)setUI{
   UIView *startView=[self dateViewWithTitle:@"起始日期"];
    startView.tag=200;
    _beginLable=[startView viewWithTag:100];
      UIView *endView=[self dateViewWithTitle:@"结束日期"];
    endView.tag=201;
    _endLable=[endView viewWithTag:100];
    
    UIView *searchView=[self searchView];
    [startView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.top.equalTo(self);
        make.width.mas_equalTo((self.width- kSearchViewW)/2);
    }];
    [endView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.top.equalTo(self);
        make.left.equalTo(startView.mas_right);
        make.width.mas_equalTo((self.width- kSearchViewW)/2);
    }];
    [searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-1);
        make.right.mas_equalTo(-1);
        make.top.mas_equalTo(1);
        make.width.mas_equalTo(kSearchViewW);
    }];
//    searchView.layer.cornerRadius=4;

    
  }



-(UIView *)dateViewWithTitle:(NSString *)title{
    UIButton *contentView=[UIButton new];
    [self addSubview:contentView];
    
    UIImageView *pic=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_date"]];
    [contentView addSubview:pic];
    [pic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.equalTo(contentView);
    }];
    
    UIImageView *down=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrows_down"]];
    [contentView addSubview:down];
    [down mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.equalTo(contentView);
    }];
  
    UILabel *lable=[[UILabel alloc] init];
    lable.font=Font(12);
    lable.tag=100;
    lable.text=title;
    lable.textColor=[UIColor colorWithHex:@"6D6D6D"];
    [lable sizeToFit];
    [contentView addSubview:lable];
    
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(contentView);
    }];
     [contentView addTarget:self action:@selector(dateButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    return contentView;


    
}
-(UIView *)searchView{

    UIButton *contentView=[UIButton new];
    contentView.backgroundColor=ThemeGreenColor;
    [self addSubview:contentView];
    
    UIImageView *pic=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_search_history"]];
    [contentView addSubview:pic];
    [pic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.equalTo(contentView);
    }];
    
       UILabel *lable=[[UILabel alloc] init];
    lable.font=Font(15);
    lable.tag=100;
    lable.text=@"查询";
    lable.textColor=[UIColor whiteColor];
    [lable sizeToFit];
    [contentView addSubview:lable];
    
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(contentView);
         make.right.mas_equalTo(-10);
    }];
    [contentView addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];
    return contentView;
    
    

}

-(void)dateButtonClick:(UIButton *)btn{
    _recordSearchBarDateClick?_recordSearchBarDateClick(btn.tag-200):nil;
}
-(void)searchBtnClick{
    _recordSearchBarSearchClick?_recordSearchBarSearchClick():nil;

}
-(void)setDateEnd:(NSString *)dateEnd{
    _dateEnd=dateEnd;
    _endLable.text=dateEnd;
}
-(void)setDateBegin:(NSString *)dateBegin{
    _dateBegin=dateBegin;
    _beginLable.text=dateBegin;
    
}
@end
